/*
**    Copyright (C) 2003-2011 Institute for Systems Biology
**                            Seattle, Washington, USA.
**
**    This library is free software; you can redistribute it and/or
**    modify it under the terms of the GNU Lesser General Public
**    License as published by the Free Software Foundation; either
**    version 3 of the License, or (at your option) any later version.
**
**    This library is distributed in the hope that it will be useful,
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
**    Lesser General Public License for more details.
**
**    You should have received a copy of the GNU Lesser General Public
**    License along with this library; if not, write to the Free Software
**    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
*/

package org.systemsbiology.iteration;

import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * An iterator that contains no elements. Implementation of the Null Pattern for an iterator.
 * It has a type only so it can be sent to anything expecting an Iterator with a type.
 * @author anorberg
 * @param <E> Theoretical yield type of the iterator. Of course, this never yields anything.
 *
 */
public class EmptyIterator<E> implements Iterator<E> {

	// implicit default constructor
	
	/**
	 * EmptyIterator never has anything, so it returns false.
	 * @return false.
	 */
	@Override
	public boolean hasNext() {
		return false;
	}

	/**
	 * EmptyIterator never has anything, so this returns null...
	 * ...after failing an assert, because you shouldn't
	 * be calling next() on an empty iterator.
	 */
	@Override
	public E next() {
		throw new NoSuchElementException("EmptyIterator is empty");
	}

	/**
	 * EmptyIterator never has anything, so this always fails.
	 * @throws NoSuchElementException - always, since there are no elements to operate on.
	 */
	@Override
	public void remove() {
		throw new NoSuchElementException("EmptyIterator never has any elements, so there is nothing to remove().");
	}

}
